package com.zzf.concurrent.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;
import java.util.UUID;

/**
 * @author GaoFeng2017
 * @date 2019/9/8 14:58
 */
public class StringUtil {
    private static final Logger logger = LoggerFactory.getLogger(StringUtil.class);

    private static final String RANDOM_BASE_STR = "1234567890abcdefghijklmnopqrstuvwxyz12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

    private static char[] hexChars = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

    /**
     * 获取指定长度的随机字符串
     * @author GaoFeng
     * @date 2018/6/13 15:31
     * @param len 生成的字符串长度
     * @return java.lang.String
     *
     */

    public static String getRandomStr(int len) {

        StringBuilder sb = new StringBuilder(len);

        for (int i = 0;i < len;i++) {
            Random random = new Random();
            sb.append(RANDOM_BASE_STR.charAt(random.nextInt(RANDOM_BASE_STR.length())));
        }

        return sb.toString();
    }

    public static String getRandomNum(int len) {
        Random random = new Random();

        StringBuilder sb = new StringBuilder(6);

        for (int i = 0; i < len; i++) {
            sb.append(random.nextInt(10));
        }

        return sb.toString();
    }


    /**
     *
     * 将字符串数组的元素进行拼接
     * @author GaoFeng
     * @date 2018/6/13 17:13
     * @param arr 要连接的字符串数组
     * @return java.lang.String
     *
     */
    public static String strArrConnect(String[] arr) {

        StringBuilder sb = new StringBuilder(arr.length);

        for (String s : arr) {
            if (s != null) {
                sb.append(s);
            }
        }

        return sb.toString();
    }

    /**
     *
     * @author ZengZhengFang
     *
     * @date 2018/7/25 17:31
     *
     * @param
     *
     * @return java.lang.String
     *
     */
    public static String getUUID() {
        return UUID.randomUUID().toString();
    }

    public static boolean isBlank(String str) {
        return str == null || str.trim().isEmpty();
    }


}
